home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Printing / STD File Saver 2.0 / Source / MyPDEF_7_PrGeneral.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-08  |  3.6 KB  |  138 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Copyright 1991-1996 Apple Computer. All rights reserved.
  3. **
  4. **    You may incorporate this sample code into your applications without
  5. **    restriction, though the sample code has been provided "AS IS" and the
  6. **    responsibility for its operation is 100% yours.  However, what you are
  7. **    not permitted to do is to redistribute the source as "DSC Sample Code"
  8. **    after having made changes. If you're going to re-distribute the source,
  9. **    we require that you make it clear in the source that the code was
  10. **    descended from Apple Sample Code, but that you've made changes.
  11. */
  12.  
  13. #include <Printing.h>
  14.  
  15. #include "driverTypes.h"
  16.  
  17. enum {    // PrGeneral result codes as defined in IM:Imaging, 9-74
  18.     prGeneralNoErr = 0,
  19.     noSuchResolution,
  20.     opcodeNotSupported
  21. };
  22.  
  23. static void GetResolution(TGetRslBlk *data)
  24. {
  25. #ifdef VAR_RESOLUTION
  26.     SysEnvRec theWorld;
  27.     SysEnvirons(1, &theWorld);
  28.  
  29.     if (!theWorld.hasColorQD) {
  30.         // if we don't have color QD, we can't have var-res
  31.         setPrintErr(noErr);
  32.         data->iRgType = VER_SHORT;
  33.         data->iError = noErr;
  34.         data->xRslRg.iMin = 0;
  35.         data->xRslRg.iMax = 0;
  36.         data->yRslRg.iMin = 0;
  37.         data->yRslRg.iMax = 0;
  38.         data->iRslRecCnt = 1;
  39.         data->rgRslRec[0].iXRsl = 72;
  40.         data->rgRslRec[0].iYRsl = 72;
  41.     } else {
  42.         // variable resolution. Wee-haw.
  43.     }
  44. #else
  45.     setPrintErr(noErr);
  46.     data->iError = noErr;
  47.     data->iRgType = VER_SHORT;
  48.     data->xRslRg.iMin = 0;
  49.     data->xRslRg.iMax = 0;
  50.     data->yRslRg.iMin = 0;
  51.     data->yRslRg.iMax = 0;
  52.     data->iRslRecCnt = 1;
  53.     data->rgRslRec[0].iXRsl = 72;
  54.     data->rgRslRec[0].iYRsl = 72;
  55. #endif
  56. }
  57.  
  58. static void SetResolution(TSetRslBlk *data)
  59. {
  60. #ifdef VAR_RESOLUTION
  61.     SysEnvRec theWorld;
  62.     SysEnvirons(1, &theWorld);
  63.  
  64.     if (!theWorld.hasColorQD) {
  65.         // we can't support setting the resolution if we only said we
  66.         // had one choice and no range. Error.
  67.         setPrintErr(opcodeNotSupported);
  68.         data->iError = opcodeNotSupported;
  69.     } else {
  70.         setPrintErr(noErr);
  71.         data->iError = noErr;
  72.         // Change the resolution to what they asked for
  73.     }
  74. #else
  75.     setPrintErr(opcodeNotSupported);
  76.     data->iError = opcodeNotSupported;
  77. #endif
  78. }
  79.  
  80. static void DraftBits(TDftBitsBlk *data)
  81. {
  82. #ifdef DEBUG
  83.     DebugStr("\pprGeneral DraftBits called, and I haven't written it yet!");
  84. #endif
  85.     setPrintErr(noErr);
  86.     data->iError = opcodeNotSupported;
  87. }
  88.  
  89. static void GetRotation(TGetRotnBlk *data)
  90. {
  91.     THPrint    printHandle = data->hPrint;
  92.     Rect    pageRect = (**printHandle).prInfo.rPage;
  93.     short    width = pageRect.right - pageRect.left;
  94.     short    height = pageRect.bottom - pageRect.top;
  95.  
  96.     // the following logic is overly simplistic and won't deal with
  97.     // pages that are designed to be landscape (i.e. ledger instead
  98.     // of tabloid), but it works for the sizes I've defined. Note
  99.     // that there just isn't a good way to deal with LEF pages in
  100.     // the old printing architecture. GX has a way of dealing with
  101.     // them, but if you were interested in GX, you wouldn't be
  102.     // looking at this sample, now would you? -DaveP
  103.  
  104.     data->fLandscape = (width > height);
  105.     data->iError = noErr;
  106.     setPrintErr(noErr);
  107. }
  108.  
  109. // refer to Inside Macintosh vol. V and the relevant Technical Notes for details 
  110. pascal void FilePrGeneral(Ptr pData)
  111. {
  112.     TGnlData *localData = (TGnlData *)pData;
  113.     setPrintErr(prGeneralNoErr);
  114.     switch (localData->iOpCode) { 
  115.         case getRslDataOp:
  116.             GetResolution((TGetRslBlk *)pData);
  117.             break;
  118.         case setRslOp:
  119.             SetResolution((TSetRslBlk *)pData);
  120.             break;
  121.         case draftBitsOp:
  122.         case noDraftBitsOp:
  123.             DraftBits((TDftBitsBlk *)pData);
  124.             break;
  125.         case getRotnOp:
  126.             GetRotation((TGetRotnBlk *)pData);
  127.             break;
  128.         default:
  129. #ifdef DEBUG
  130.             DebugStr("\pprGeneral called with a selctor I don't understand.");
  131. #endif
  132.             setPrintErr(opcodeNotSupported);
  133.             localData->iError = opcodeNotSupported;
  134.             break;
  135.     }
  136. }
  137.  
  138.